package com.imooc.order.controller;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.imooc.order.client.ProductClient;
import com.imooc.order.dataobject.ProductInfo;
import com.imooc.order.dto.CartDTO;

import lombok.extern.slf4j.Slf4j;

/**
 * @author morrow
 * @date 2019年1月1日
 * 
 */
@RestController
@Slf4j
public class ClientController {

	/*
	 * @Autowired private RestTemplate restTemplate;
	 */
	@Autowired
	private ProductClient productClient;

	@GetMapping("/getProductMsg")
	public String getProductMsg() {
//		String msg = restTemplate.getForObject("http://PRODUCT/msg", String.class);
		String msg = productClient.productMsg();
		log.info("product msg = {}", msg);
		return msg;
	}

	@GetMapping("/getProductForOrder")
	public String getProductForOrder() {
		List<ProductInfo> productInfoList = productClient
				.listForOrder(Arrays.asList("157875196366160022", "157875196366160023"));
		log.info("method = {}, productInfoList = {}", "listForOrder", productInfoList);
		return "ok";
	}

	@GetMapping("/decreaseStock")
	public String decreaseStock() {
		productClient.decreaseStock(
				Arrays.asList(new CartDTO("157875196366160023", 2), new CartDTO("157875196366160024", 2)));
		return "ok";
	}

}
